home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / oop_tp55.zip / LIST10_2.PAS < prev    next >
Pascal/Delphi Source File  |  1990-02-20  |  3KB  |  91 lines

  1. unit List10_2; { Listing 10-2 }
  2.  
  3. interface
  4.  
  5. uses Graph, Mouse, Crt, ProRobot;
  6.  
  7. type
  8.  
  9. RobotArm = object( Segment )
  10.            procedure Init( AnchorX, AnchorY, ArmLen : Integer;
  11.                            Position : Degrees;
  12.                            DispQ : Boolean );
  13.            procedure MoveTo( APoint : Point );
  14.            procedure ShowBase;
  15.            procedure ShowLimit;
  16.            end;
  17.  
  18. implementation
  19.  
  20. procedure RobotArm.Init( AnchorX, AnchorY, ArmLen : Integer;
  21.                          Position : Degrees;
  22.                          DispQ : Boolean );
  23. begin
  24.      Segment.Init( AnchorX, AnchorY, ArmLen, Position );
  25.      if DispQ = true then
  26.         begin
  27.         Show;
  28.         ShowBase;
  29.         end;
  30. end;
  31.  
  32. procedure RobotArm.MoveTo( APoint : Point );
  33.  
  34. var D : real;
  35.     RotDelta : integer;
  36.     AxDelta  : integer;
  37. begin
  38.       { Phase 1 }
  39.           RotDelta := 1;
  40.           D := Distance( APoint, BusyEnd );  { find distance }
  41.           Rotate( RotDelta );                  { rotate }
  42.           if D < Distance( APoint, BusyEnd ) then begin
  43.              { if new distance is greater than old distance }
  44.              D := Distance( APoint, BusyEnd ); { set distance }
  45.              RotDelta := -RotDelta;  { reverse direction of rotation }
  46.              Rotate( RotDelta ); { rotate in opposite direction }
  47.              end;
  48.           while D > Distance( APoint, BusyEnd ) do begin
  49.                 { new distance should be less than old }
  50.                 D :=  Distance( APoint, BusyEnd );
  51.                 Rotate( RotDelta );
  52.                 end;
  53.                 { stops when Distance starts to get big again }
  54.           RotDelta := -RotDelta;
  55.           Rotate( RotDelta ); { go back one }
  56.           { End of Phase 1 }
  57.      { Phase 2 }
  58.      AxDelta := 4;
  59.      { set distance }
  60.      D := Distance( APoint, BusyEnd );
  61.      MoveAxial( AxDelta );  { move axially }
  62.      if D < Distance( APoint, BusyEnd ) then begin
  63.         D := Distance( APoint, BusyEnd );
  64.         AxDelta := -AxDelta;
  65.         MoveAxial( AxDelta );
  66.         end;
  67.      while D > Distance( APoint, BusyEnd ) do begin
  68.         D :=  Distance( APoint, BusyEnd );
  69.         MoveAxial( AxDelta );
  70.         end;
  71.      AxDelta := -AxDelta div 2;
  72.      MoveAxial( AxDelta );  { should be here }
  73.      ShowLimit;
  74.      ShowBase;
  75.      { End of Phase 2 }
  76. end;
  77.  
  78. procedure RobotArm.ShowBase;
  79. begin
  80.      with Anchor do
  81.           Graph.PieSlice(X, Y, 268, 272, Round(GetMaxY/2.2));
  82. end;
  83.  
  84. procedure RobotArm.ShowLimit;
  85. begin
  86.      SetColor( red );
  87.      with Anchor do
  88.           Circle( X, Y, Length );
  89.      SetColor( white );
  90. end;
  91. end.